<template>
  <!-- 进度节点信息 -->
  <div style="height:520px">
    <!-- table -->
    <FilterTable
      ref="table"
      height="430"
      :columns="columns"
      :isSelectColumn="isSelectColumn"
      :fetchapi="fetchParams"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" v-if="value.type!=='show'">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="addHandle(123,'add')">新增</el-button>
      </template>
    </FilterTable>
    <BaseDialog
      title="进度节点新增"
      :visible.sync="visibleAdd"
      width="400px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <addModal ref="addDialog" @close="closeHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import addModal from './infoScheduleModal';

export default {
  mixins: [dictionary],
  components: {
    addModal
  },
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      visibleAdd: false,
      isSelectColumn: false,
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: null //ipa 接口
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
  },
  methods: {
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.addHandle(props.row, 'edit')}>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text">
                  删除
                </el-button>
              </div>
            );
          }
        },
        {
          title: '进度节点类型',
          dataIndex: 'field2',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        },
        { title: '时间', dataIndex: 'field3', sorter: true },
        {
          title: '附件',
          dataIndex: 'field4',
          sorter: true,
          unitRender: () => {
            return (
              <el-button slot="append" icon="el-icon-search">
                附件.xls
              </el-button>
            );
          }
        }
      ];
    },
    //详情
    addHandle(row, type) {
      //逻辑自己写
      this.initData = {
        type: 'add', //add/edit/show
        id: 1001
      }; //行id
      this.visibleAdd = true;
    },
    closeHandler(data) {
      this.visibleAdd = data.visible;
    }
  }
};
</script>